package com.example.SpringBootdemo;

import jakarta.servlet.http.HttpServletRequest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.nacos.api.config.annotation.NacosValue;

@RestController
@EnableAutoConfiguration
@Component
public class HelloWorldController {

    @NacosValue(value = "${redis.hostAndPort}", autoRefreshed = true)
	private String hostAndPort;
    @Value("${redis.redisPassWord}")
	private String redisPassWord;

	private static String hostsAndPorts;

	@Value("${mongo.hostsAndPorts}")
	public void setHostsAndPorts(String inHostsAndPorts) {
		hostsAndPorts = inHostsAndPorts;
	}

	private static String userNameDatabasePassword;

	@Value("${mongo.userNameDatabasePassword}")
	public void setUserNameDatabasePassword(String inUserNameDatabasePassword) {
		userNameDatabasePassword = inUserNameDatabasePassword;
	}

	private static final Logger logger = LogManager.getLogger();
	@RequestMapping("/hello")
    public String index(HttpServletRequest request) {
		String username=request.getParameter("username");
        String password=request.getParameter("password");
        System.out.println("username is:"+username);
        System.out.println("password is:"+password);
        logger.info(username + password);
        logger.info("配置内容是："+ hostAndPort + redisPassWord + hostsAndPorts + userNameDatabasePassword);
        return "Hello World" + username + "配置内容是："+ hostAndPort + redisPassWord + hostsAndPorts + userNameDatabasePassword;
    }
	public static void main(String[] args) {
        SpringApplication.run(HelloWorldController.class, args);
//		String selectSql = "select * from tb_emp1";
//		String insertSql = "insert tb_emp1 values(11,'张三',123,12.12)";
//		String insertSql = "insert customers values(11,'张三','上海')";
    }
}
